<?php
namespace app\driving\controller;

use think\Controller;
use app\base\controller\Base;
use think\Validate;
use think\Db;


class Login extends Common
{   
    private $Base;
   
    public function __construct(){
        parent::__construct();
        $this->Base = new Base();

    }

    public function index (){   
        $result = $this->Base->login();
        return json(['msg'=>'登录成功！','code'=>1,'token'=> $result]);
    }

    public function addUser(){
        $info['type'] = input('type');
        //添加用户信息
        $this->Base->addUserInfo($this->user);
        //添加用户选择驾驶证类型
        $time = time();
        $info['update_time'] = $time;
        if($result = Db::name('driving_type')->where('user_id',$this->userId)->find()){
            $result = Db::name('driving_type')->where('id',$result['id'])->update($info);
        }else{
            $info['user_id']     = $this->userId;
            $info['create_time'] = $time;
            Db::name('driving_type')->insert($info);
        }

        return json(['msg' => '修改成功','code'=>1,'type'=>$info['type']]);

    }

    public function getQuestionList()
    {   
        //添加用户信息
        $type    = input('type');
        $subject = input('subject');

        $type = input('type');
        $data['question_list'] = Db::name('driving_test')->where('type',$type)->where('subject',$subject)->select();      
        return $data;
    }
}